# import tkinter as tk

# class App(tk.Frame):
#     def __init__(self, master):
#         super().__init__(master)
#         self.pack()

#         self.entrythingy = tk.Entry()
#         self.entrythingy.pack()

#         # Create the application variable.
#         self.contents = tk.StringVar()
#         # Set it to some value.
#         self.contents.set("this is a variable")
#         # Tell the entry widget to watch this variable.
#         self.entrythingy["textvariable"] = self.contents

#         # Define a callback for when the user hits return.
#         # It prints the current value of the variable.
#         self.entrythingy.bind('<Key-Return>',
#                              self.print_contents)

#     def print_contents(self, event):
#         print("Hi. The current entry content is:",
#               self.contents.get())

# root = tk.Tk()
# myapp = App(root)
# myapp.mainloop()


import tkinter as tk
from tkinter import ttk
 
def load_more():
    # 模拟加载更多数据的函数
    print("正在加载...")
    listbox.insert(tk.END, f"Item {i++1}")
    
root = tk.Tk()
scrollbar = ttk.Scrollbar(root)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
listbox = tk.Listbox(root, yscrollcommand=scrollbar.set)
listbox.bind("<Button-4>", lambda event: listbox.yview_scroll(-1, "units"))
listbox.bind("<Button-5>", lambda event: listbox.yview_scroll(1, "units"))
listbox.config(yscrollcommand=scrollbar.set)
listbox.pack(fill=tk.BOTH, expand=True)
 
# 添加初始数据到列表框
for i in range(20):
    listbox.insert(tk.END, f"Item {i+1}")
 
load_button = tk.Button(root, text="加载更多", command=load_more)
load_button.pack()
 
root.mainloop()